﻿using System;
using UnityEngine;

namespace ParticlePlayground
{
	// Token: 0x020001AC RID: 428
	public class SimplexNoise
	{
		// Token: 0x060009C4 RID: 2500 RVA: 0x000499C0 File Offset: 0x00047BC0
		static SimplexNoise()
		{
			int[][] array = new int[12][];
			int num = 0;
			int[] array2 = new int[3];
			array2[0] = 1;
			array2[1] = 1;
			array[num] = array2;
			int num2 = 1;
			int[] array3 = new int[3];
			array3[0] = -1;
			array3[1] = 1;
			array[num2] = array3;
			int num3 = 2;
			int[] array4 = new int[3];
			array4[0] = 1;
			array4[1] = -1;
			array[num3] = array4;
			int num4 = 3;
			int[] array5 = new int[3];
			array5[0] = -1;
			array5[1] = -1;
			array[num4] = array5;
			array[4] = new int[]
			{
				1,
				0,
				1
			};
			array[5] = new int[]
			{
				-1,
				0,
				1
			};
			array[6] = new int[]
			{
				1,
				0,
				-1
			};
			array[7] = new int[]
			{
				-1,
				0,
				-1
			};
			array[8] = new int[]
			{
				0,
				1,
				1
			};
			array[9] = new int[]
			{
				0,
				-1,
				1
			};
			array[10] = new int[]
			{
				0,
				1,
				-1
			};
			array[11] = new int[]
			{
				0,
				-1,
				-1
			};
			SimplexNoise.grad3 = array;
			int[][] array6 = new int[32][];
			array6[0] = new int[]
			{
				0,
				1,
				1,
				1
			};
			array6[1] = new int[]
			{
				0,
				1,
				1,
				-1
			};
			array6[2] = new int[]
			{
				0,
				1,
				-1,
				1
			};
			array6[3] = new int[]
			{
				0,
				1,
				-1,
				-1
			};
			array6[4] = new int[]
			{
				0,
				-1,
				1,
				1
			};
			array6[5] = new int[]
			{
				0,
				-1,
				1,
				-1
			};
			array6[6] = new int[]
			{
				0,
				-1,
				-1,
				1
			};
			array6[7] = new int[]
			{
				0,
				-1,
				-1,
				-1
			};
			array6[8] = new int[]
			{
				1,
				0,
				1,
				1
			};
			array6[9] = new int[]
			{
				1,
				0,
				1,
				-1
			};
			array6[10] = new int[]
			{
				1,
				0,
				-1,
				1
			};
			array6[11] = new int[]
			{
				1,
				0,
				-1,
				-1
			};
			array6[12] = new int[]
			{
				-1,
				0,
				1,
				1
			};
			array6[13] = new int[]
			{
				-1,
				0,
				1,
				-1
			};
			array6[14] = new int[]
			{
				-1,
				0,
				-1,
				1
			};
			array6[15] = new int[]
			{
				-1,
				0,
				-1,
				-1
			};
			array6[16] = new int[]
			{
				1,
				1,
				0,
				1
			};
			array6[17] = new int[]
			{
				1,
				1,
				0,
				-1
			};
			array6[18] = new int[]
			{
				1,
				-1,
				0,
				1
			};
			array6[19] = new int[]
			{
				1,
				-1,
				0,
				-1
			};
			array6[20] = new int[]
			{
				-1,
				1,
				0,
				1
			};
			array6[21] = new int[]
			{
				-1,
				1,
				0,
				-1
			};
			array6[22] = new int[]
			{
				-1,
				-1,
				0,
				1
			};
			array6[23] = new int[]
			{
				-1,
				-1,
				0,
				-1
			};
			int num5 = 24;
			int[] array7 = new int[4];
			array7[0] = 1;
			array7[1] = 1;
			array7[2] = 1;
			array6[num5] = array7;
			int num6 = 25;
			int[] array8 = new int[4];
			array8[0] = 1;
			array8[1] = 1;
			array8[2] = -1;
			array6[num6] = array8;
			int num7 = 26;
			int[] array9 = new int[4];
			array9[0] = 1;
			array9[1] = -1;
			array9[2] = 1;
			array6[num7] = array9;
			int num8 = 27;
			int[] array10 = new int[4];
			array10[0] = 1;
			array10[1] = -1;
			array10[2] = -1;
			array6[num8] = array10;
			int num9 = 28;
			int[] array11 = new int[4];
			array11[0] = -1;
			array11[1] = 1;
			array11[2] = 1;
			array6[num9] = array11;
			int num10 = 29;
			int[] array12 = new int[4];
			array12[0] = -1;
			array12[1] = 1;
			array12[2] = -1;
			array6[num10] = array12;
			int num11 = 30;
			int[] array13 = new int[4];
			array13[0] = -1;
			array13[1] = -1;
			array13[2] = 1;
			array6[num11] = array13;
			int num12 = 31;
			int[] array14 = new int[4];
			array14[0] = -1;
			array14[1] = -1;
			array14[2] = -1;
			array6[num12] = array14;
			SimplexNoise.grad4 = array6;
			SimplexNoise.p = new int[]
			{
				151,
				160,
				137,
				91,
				90,
				15,
				131,
				13,
				201,
				95,
				96,
				53,
				194,
				233,
				7,
				225,
				140,
				36,
				103,
				30,
				69,
				142,
				8,
				99,
				37,
				240,
				21,
				10,
				23,
				190,
				6,
				148,
				247,
				120,
				234,
				75,
				0,
				26,
				197,
				62,
				94,
				252,
				219,
				203,
				117,
				35,
				11,
				32,
				57,
				177,
				33,
				88,
				237,
				149,
				56,
				87,
				174,
				20,
				125,
				136,
				171,
				168,
				68,
				175,
				74,
				165,
				71,
				134,
				139,
				48,
				27,
				166,
				77,
				146,
				158,
				231,
				83,
				111,
				229,
				122,
				60,
				211,
				133,
				230,
				220,
				105,
				92,
				41,
				55,
				46,
				245,
				40,
				244,
				102,
				143,
				54,
				65,
				25,
				63,
				161,
				1,
				216,
				80,
				73,
				209,
				76,
				132,
				187,
				208,
				89,
				18,
				169,
				200,
				196,
				135,
				130,
				116,
				188,
				159,
				86,
				164,
				100,
				109,
				198,
				173,
				186,
				3,
				64,
				52,
				217,
				226,
				250,
				124,
				123,
				5,
				202,
				38,
				147,
				118,
				126,
				255,
				82,
				85,
				212,
				207,
				206,
				59,
				227,
				47,
				16,
				58,
				17,
				182,
				189,
				28,
				42,
				223,
				183,
				170,
				213,
				119,
				248,
				152,
				2,
				44,
				154,
				163,
				70,
				221,
				153,
				101,
				155,
				167,
				43,
				172,
				9,
				129,
				22,
				39,
				253,
				19,
				98,
				108,
				110,
				79,
				113,
				224,
				232,
				178,
				185,
				112,
				104,
				218,
				246,
				97,
				228,
				251,
				34,
				242,
				193,
				238,
				210,
				144,
				12,
				191,
				179,
				162,
				241,
				81,
				51,
				145,
				235,
				249,
				14,
				239,
				107,
				49,
				192,
				214,
				31,
				181,
				199,
				106,
				157,
				184,
				84,
				204,
				176,
				115,
				121,
				50,
				45,
				127,
				4,
				150,
				254,
				138,
				236,
				205,
				93,
				222,
				114,
				67,
				29,
				24,
				72,
				243,
				141,
				128,
				195,
				78,
				66,
				215,
				61,
				156,
				180
			};
			SimplexNoise.perm = new int[512];
			int[][] array15 = new int[64][];
			array15[0] = new int[]
			{
				0,
				1,
				2,
				3
			};
			array15[1] = new int[]
			{
				0,
				1,
				3,
				2
			};
			array15[2] = new int[4];
			array15[3] = new int[]
			{
				0,
				2,
				3,
				1
			};
			array15[4] = new int[4];
			array15[5] = new int[4];
			array15[6] = new int[4];
			int num13 = 7;
			int[] array16 = new int[4];
			array16[0] = 1;
			array16[1] = 2;
			array16[2] = 3;
			array15[num13] = array16;
			array15[8] = new int[]
			{
				0,
				2,
				1,
				3
			};
			array15[9] = new int[4];
			array15[10] = new int[]
			{
				0,
				3,
				1,
				2
			};
			array15[11] = new int[]
			{
				0,
				3,
				2,
				1
			};
			array15[12] = new int[4];
			array15[13] = new int[4];
			array15[14] = new int[4];
			int num14 = 15;
			int[] array17 = new int[4];
			array17[0] = 1;
			array17[1] = 3;
			array17[2] = 2;
			array15[num14] = array17;
			array15[16] = new int[4];
			array15[17] = new int[4];
			array15[18] = new int[4];
			array15[19] = new int[4];
			array15[20] = new int[4];
			array15[21] = new int[4];
			array15[22] = new int[4];
			array15[23] = new int[4];
			array15[24] = new int[]
			{
				1,
				2,
				0,
				3
			};
			array15[25] = new int[4];
			array15[26] = new int[]
			{
				1,
				3,
				0,
				2
			};
			array15[27] = new int[4];
			array15[28] = new int[4];
			array15[29] = new int[4];
			array15[30] = new int[]
			{
				2,
				3,
				0,
				1
			};
			int num15 = 31;
			int[] array18 = new int[4];
			array18[0] = 2;
			array18[1] = 3;
			array18[2] = 1;
			array15[num15] = array18;
			array15[32] = new int[]
			{
				1,
				0,
				2,
				3
			};
			array15[33] = new int[]
			{
				1,
				0,
				3,
				2
			};
			array15[34] = new int[4];
			array15[35] = new int[4];
			array15[36] = new int[4];
			array15[37] = new int[]
			{
				2,
				0,
				3,
				1
			};
			array15[38] = new int[4];
			int num16 = 39;
			int[] array19 = new int[4];
			array19[0] = 2;
			array19[1] = 1;
			array19[2] = 3;
			array15[num16] = array19;
			array15[40] = new int[4];
			array15[41] = new int[4];
			array15[42] = new int[4];
			array15[43] = new int[4];
			array15[44] = new int[4];
			array15[45] = new int[4];
			array15[46] = new int[4];
			array15[47] = new int[4];
			array15[48] = new int[]
			{
				2,
				0,
				1,
				3
			};
			array15[49] = new int[4];
			array15[50] = new int[4];
			array15[51] = new int[4];
			array15[52] = new int[]
			{
				3,
				0,
				1,
				2
			};
			array15[53] = new int[]
			{
				3,
				0,
				2,
				1
			};
			array15[54] = new int[4];
			int num17 = 55;
			int[] array20 = new int[4];
			array20[0] = 3;
			array20[1] = 1;
			array20[2] = 2;
			array15[num17] = array20;
			array15[56] = new int[]
			{
				2,
				1,
				0,
				3
			};
			array15[57] = new int[4];
			array15[58] = new int[4];
			array15[59] = new int[4];
			array15[60] = new int[]
			{
				3,
				1,
				0,
				2
			};
			array15[61] = new int[4];
			array15[62] = new int[]
			{
				3,
				2,
				0,
				1
			};
			int num18 = 63;
			int[] array21 = new int[4];
			array21[0] = 3;
			array21[1] = 2;
			array21[2] = 1;
			array15[num18] = array21;
			SimplexNoise.simplex = array15;
			for (int i = 0; i < 512; i++)
			{
				SimplexNoise.perm[i] = SimplexNoise.p[i & 255];
			}
		}

		// Token: 0x060009C5 RID: 2501 RVA: 0x0004A164 File Offset: 0x00048364
		private static int fastfloor(double x)
		{
			return (x <= 0.0) ? ((int)x - 1) : ((int)x);
		}

		// Token: 0x060009C6 RID: 2502 RVA: 0x0004A180 File Offset: 0x00048380
		private static double dot(int[] g, double x, double y)
		{
			return (double)g[0] * x + (double)g[1] * y;
		}

		// Token: 0x060009C7 RID: 2503 RVA: 0x0004A190 File Offset: 0x00048390
		private static double dot(int[] g, double x, double y, double z)
		{
			return (double)g[0] * x + (double)g[1] * y + (double)g[2] * z;
		}

		// Token: 0x060009C8 RID: 2504 RVA: 0x0004A1A8 File Offset: 0x000483A8
		private static double dot(int[] g, double x, double y, double z, double w)
		{
			return (double)g[0] * x + (double)g[1] * y + (double)g[2] * z + (double)g[3] * w;
		}

		// Token: 0x060009C9 RID: 2505 RVA: 0x0004A1C8 File Offset: 0x000483C8
		public virtual double noise(double xin, double yin, double zin)
		{
			double num = 0.33333333333333331;
			double num2 = (xin + yin + zin) * num;
			int num3 = SimplexNoise.fastfloor(xin + num2);
			int num4 = SimplexNoise.fastfloor(yin + num2);
			int num5 = SimplexNoise.fastfloor(zin + num2);
			double num6 = 0.16666666666666666;
			double num7 = (double)(num3 + num4 + num5) * num6;
			double num8 = (double)num3 - num7;
			double num9 = (double)num4 - num7;
			double num10 = (double)num5 - num7;
			double num11 = xin - num8;
			double num12 = yin - num9;
			double num13 = zin - num10;
			int num14;
			int num15;
			int num16;
			int num17;
			int num18;
			int num19;
			if (num11 >= num12)
			{
				if (num12 >= num13)
				{
					num14 = 1;
					num15 = 0;
					num16 = 0;
					num17 = 1;
					num18 = 1;
					num19 = 0;
				}
				else if (num11 >= num13)
				{
					num14 = 1;
					num15 = 0;
					num16 = 0;
					num17 = 1;
					num18 = 0;
					num19 = 1;
				}
				else
				{
					num14 = 0;
					num15 = 0;
					num16 = 1;
					num17 = 1;
					num18 = 0;
					num19 = 1;
				}
			}
			else if (num12 < num13)
			{
				num14 = 0;
				num15 = 0;
				num16 = 1;
				num17 = 0;
				num18 = 1;
				num19 = 1;
			}
			else if (num11 < num13)
			{
				num14 = 0;
				num15 = 1;
				num16 = 0;
				num17 = 0;
				num18 = 1;
				num19 = 1;
			}
			else
			{
				num14 = 0;
				num15 = 1;
				num16 = 0;
				num17 = 1;
				num18 = 1;
				num19 = 0;
			}
			double num20 = num11 - (double)num14 + num6;
			double num21 = num12 - (double)num15 + num6;
			double num22 = num13 - (double)num16 + num6;
			double num23 = num11 - (double)num17 + 2.0 * num6;
			double num24 = num12 - (double)num18 + 2.0 * num6;
			double num25 = num13 - (double)num19 + 2.0 * num6;
			double num26 = num11 - 1.0 + 3.0 * num6;
			double num27 = num12 - 1.0 + 3.0 * num6;
			double num28 = num13 - 1.0 + 3.0 * num6;
			int num29 = num3 & 255;
			int num30 = num4 & 255;
			int num31 = num5 & 255;
			int num32 = SimplexNoise.perm[num29 + SimplexNoise.perm[num30 + SimplexNoise.perm[num31]]] % 12;
			int num33 = SimplexNoise.perm[num29 + num14 + SimplexNoise.perm[num30 + num15 + SimplexNoise.perm[num31 + num16]]] % 12;
			int num34 = SimplexNoise.perm[num29 + num17 + SimplexNoise.perm[num30 + num18 + SimplexNoise.perm[num31 + num19]]] % 12;
			int num35 = SimplexNoise.perm[num29 + 1 + SimplexNoise.perm[num30 + 1 + SimplexNoise.perm[num31 + 1]]] % 12;
			double num36 = 0.5 - num11 * num11 - num12 * num12 - num13 * num13;
			double num37;
			if (num36 < 0.0)
			{
				num37 = 0.0;
			}
			else
			{
				num36 *= num36;
				num37 = num36 * num36 * SimplexNoise.dot(SimplexNoise.grad3[num32], num11, num12, num13);
			}
			double num38 = 0.6 - num20 * num20 - num21 * num21 - num22 * num22;
			double num39;
			if (num38 < 0.0)
			{
				num39 = 0.0;
			}
			else
			{
				num38 *= num38;
				num39 = num38 * num38 * SimplexNoise.dot(SimplexNoise.grad3[num33], num20, num21, num22);
			}
			double num40 = 0.6 - num23 * num23 - num24 * num24 - num25 * num25;
			double num41;
			if (num40 < 0.0)
			{
				num41 = 0.0;
			}
			else
			{
				num40 *= num40;
				num41 = num40 * num40 * SimplexNoise.dot(SimplexNoise.grad3[num34], num23, num24, num25);
			}
			double num42 = 0.6 - num26 * num26 - num27 * num27 - num28 * num28;
			double num43;
			if (num42 < 0.0)
			{
				num43 = 0.0;
			}
			else
			{
				num42 *= num42;
				num43 = num42 * num42 * SimplexNoise.dot(SimplexNoise.grad3[num35], num26, num27, num28);
			}
			return 32.0 * (num37 + num39 + num41 + num43);
		}

		// Token: 0x060009CA RID: 2506 RVA: 0x0004A5E8 File Offset: 0x000487E8
		public virtual double noise(double x, double y, double z, double w)
		{
			double num = ((double)Mathf.Sqrt(5f) - 1.0) / 4.0;
			double num2 = (5.0 - (double)Mathf.Sqrt(5f)) / 20.0;
			double num3 = (x + y + z + w) * num;
			int num4 = SimplexNoise.fastfloor(x + num3);
			int num5 = SimplexNoise.fastfloor(y + num3);
			int num6 = SimplexNoise.fastfloor(z + num3);
			int num7 = SimplexNoise.fastfloor(w + num3);
			double num8 = (double)(num4 + num5 + num6 + num7) * num2;
			double num9 = (double)num4 - num8;
			double num10 = (double)num5 - num8;
			double num11 = (double)num6 - num8;
			double num12 = (double)num7 - num8;
			double num13 = x - num9;
			double num14 = y - num10;
			double num15 = z - num11;
			double num16 = w - num12;
			int num17 = (num13 <= num14) ? 0 : 32;
			int num18 = (num13 <= num15) ? 0 : 16;
			int num19 = (num14 <= num15) ? 0 : 8;
			int num20 = (num13 <= num16) ? 0 : 4;
			int num21 = (num14 <= num16) ? 0 : 2;
			int num22 = (num15 <= num16) ? 0 : 1;
			int num23 = num17 + num18 + num19 + num20 + num21 + num22;
			int num24 = (SimplexNoise.simplex[num23][0] < 3) ? 0 : 1;
			int num25 = (SimplexNoise.simplex[num23][1] < 3) ? 0 : 1;
			int num26 = (SimplexNoise.simplex[num23][2] < 3) ? 0 : 1;
			int num27 = (SimplexNoise.simplex[num23][3] < 3) ? 0 : 1;
			int num28 = (SimplexNoise.simplex[num23][0] < 2) ? 0 : 1;
			int num29 = (SimplexNoise.simplex[num23][1] < 2) ? 0 : 1;
			int num30 = (SimplexNoise.simplex[num23][2] < 2) ? 0 : 1;
			int num31 = (SimplexNoise.simplex[num23][3] < 2) ? 0 : 1;
			int num32 = (SimplexNoise.simplex[num23][0] < 1) ? 0 : 1;
			int num33 = (SimplexNoise.simplex[num23][1] < 1) ? 0 : 1;
			int num34 = (SimplexNoise.simplex[num23][2] < 1) ? 0 : 1;
			int num35 = (SimplexNoise.simplex[num23][3] < 1) ? 0 : 1;
			double num36 = num13 - (double)num24 + num2;
			double num37 = num14 - (double)num25 + num2;
			double num38 = num15 - (double)num26 + num2;
			double num39 = num16 - (double)num27 + num2;
			double num40 = num13 - (double)num28 + 2.0 * num2;
			double num41 = num14 - (double)num29 + 2.0 * num2;
			double num42 = num15 - (double)num30 + 2.0 * num2;
			double num43 = num16 - (double)num31 + 2.0 * num2;
			double num44 = num13 - (double)num32 + 3.0 * num2;
			double num45 = num14 - (double)num33 + 3.0 * num2;
			double num46 = num15 - (double)num34 + 3.0 * num2;
			double num47 = num16 - (double)num35 + 3.0 * num2;
			double num48 = num13 - 1.0 + 4.0 * num2;
			double num49 = num14 - 1.0 + 4.0 * num2;
			double num50 = num15 - 1.0 + 4.0 * num2;
			double num51 = num16 - 1.0 + 4.0 * num2;
			int num52 = num4 & 255;
			int num53 = num5 & 255;
			int num54 = num6 & 255;
			int num55 = num7 & 255;
			int num56 = SimplexNoise.perm[num52 + SimplexNoise.perm[num53 + SimplexNoise.perm[num54 + SimplexNoise.perm[num55]]]] % 32;
			int num57 = SimplexNoise.perm[num52 + num24 + SimplexNoise.perm[num53 + num25 + SimplexNoise.perm[num54 + num26 + SimplexNoise.perm[num55 + num27]]]] % 32;
			int num58 = SimplexNoise.perm[num52 + num28 + SimplexNoise.perm[num53 + num29 + SimplexNoise.perm[num54 + num30 + SimplexNoise.perm[num55 + num31]]]] % 32;
			int num59 = SimplexNoise.perm[num52 + num32 + SimplexNoise.perm[num53 + num33 + SimplexNoise.perm[num54 + num34 + SimplexNoise.perm[num55 + num35]]]] % 32;
			int num60 = SimplexNoise.perm[num52 + 1 + SimplexNoise.perm[num53 + 1 + SimplexNoise.perm[num54 + 1 + SimplexNoise.perm[num55 + 1]]]] % 32;
			double num61 = 0.5 - num13 * num13 - num14 * num14 - num15 * num15 - num16 * num16;
			double num62;
			if (num61 < 0.0)
			{
				num62 = 0.0;
			}
			else
			{
				num61 *= num61;
				num62 = num61 * num61 * SimplexNoise.dot(SimplexNoise.grad4[num56], num13, num14, num15, num16);
			}
			double num63 = 0.6 - num36 * num36 - num37 * num37 - num38 * num38 - num39 * num39;
			double num64;
			if (num63 < 0.0)
			{
				num64 = 0.0;
			}
			else
			{
				num63 *= num63;
				num64 = num63 * num63 * SimplexNoise.dot(SimplexNoise.grad4[num57], num36, num37, num38, num39);
			}
			double num65 = 0.6 - num40 * num40 - num41 * num41 - num42 * num42 - num43 * num43;
			double num66;
			if (num65 < 0.0)
			{
				num66 = 0.0;
			}
			else
			{
				num65 *= num65;
				num66 = num65 * num65 * SimplexNoise.dot(SimplexNoise.grad4[num58], num40, num41, num42, num43);
			}
			double num67 = 0.6 - num44 * num44 - num45 * num45 - num46 * num46 - num47 * num47;
			double num68;
			if (num67 < 0.0)
			{
				num68 = 0.0;
			}
			else
			{
				num67 *= num67;
				num68 = num67 * num67 * SimplexNoise.dot(SimplexNoise.grad4[num59], num44, num45, num46, num47);
			}
			double num69 = 0.6 - num48 * num48 - num49 * num49 - num50 * num50 - num51 * num51;
			double num70;
			if (num69 < 0.0)
			{
				num70 = 0.0;
			}
			else
			{
				num69 *= num69;
				num70 = num69 * num69 * SimplexNoise.dot(SimplexNoise.grad4[num60], num48, num49, num50, num51);
			}
			return 27.0 * (num62 + num64 + num66 + num68 + num70);
		}

		// Token: 0x04000B95 RID: 2965
		protected static int[][] grad3;

		// Token: 0x04000B96 RID: 2966
		protected static int[][] grad4;

		// Token: 0x04000B97 RID: 2967
		protected static int[] p;

		// Token: 0x04000B98 RID: 2968
		protected static int[] perm;

		// Token: 0x04000B99 RID: 2969
		protected static int[][] simplex;
	}
}
